package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletResponse;

/*
* 会员相关接口
* */
@Slf4j
@RestController
@RequestMapping("/report")
public class MemberController {

    @Autowired
    private MemberService memberService;

    //获取会员数量统计数据
    @GetMapping("/getMemberReport")
    public Result getMemberReport() throws Exception {

        return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,memberService.getMemberReport());
    }
    //获取套餐占比统计数据
    @GetMapping("/getSetmealReport")
    public Result getSetmealReport() throws Exception {

        return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,memberService.getSetmealReport());
    }

    //获取运营统计数据
    @GetMapping("/getBusinessReportData")
    public Result getBusinessReportData() throws Exception {

        return new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS,memberService.getBusinessReportData());
    }

    //导出运营数据到Excel并提供客户端下载
    @GetMapping("/exportBusinessReport")
    public String exportBusinessReport(HttpServletResponse response )  {

        memberService.outputExcel(response);

        return "文件下载";
    }
}
